package com.yao.wechat.controller;

import com.yao.common.helper.ValidateHelper;
import com.yao.common.resp.ApiResponse;
import com.yao.wechat.entity.dto.PublicDto;
import com.yao.wechat.service.PublicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 微信公众号表 Controller
 *
 * @author autoCode
 * @version 1.0.0-SNAPSHOT
 * @date 2020-07-23
 */
@Api(tags = "公众号管理")
@RestController
@RequestMapping(value = "/public")
@Slf4j
public class PublicController {

    @Autowired
    private PublicService publicService;

    @ApiOperation(value = "新增公众号", notes = "新增公众号")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ApiResponse<Object> add(@RequestBody PublicDto model) {
        return ApiResponse.success();
    }

    @ApiOperation(value = "修改公众号", notes = "修改公众号")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ApiResponse<Object> update(@RequestBody PublicDto model) {
        return ApiResponse.success();
    }

    @ApiOperation(value = "删除公众号", notes = "逻辑删除公众号")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public ApiResponse<Object> deleteById(@PathVariable("id") Integer id) {
        return ApiResponse.success();
    }


    @ApiOperation(value = "获取微信token", notes = "获取微信token")
    @RequestMapping(value = "/getTokenByOriginId", method = RequestMethod.GET)
    public ApiResponse<String> getAccessToken(String originId){

        ValidateHelper.validateStr(originId);

        return ApiResponse.success(publicService.getAccessToken(originId));
    }

    @ApiOperation(value = "刷新微信token", notes = "刷新微信token")
    @RequestMapping(value = "/refreshToken", method = RequestMethod.GET)
    public ApiResponse<String> refreshToken(String originId){

        ValidateHelper.validateStr(originId);

        return ApiResponse.success(publicService.refreshAccessToken(originId));
    }

}